import unittest,time
from selenium import webdriver
from poium import Page,Element

class LoginPage(Page):
    login_button1 = Element(css='span[data-type="tuzhan"]')
    accounts = Element(css='input[placeholder="请输入你的登录账户"]')
    passwords = Element(css='input[placeholder="请输入密码"]')
    login_button2 = Element(css='button.g-btn.login-btn.do-btn')
    error_tip = Element(css='div.login-form span.error-tips')

    def login(self,account,password):
        self.login_button1.click()
        self.accounts.input(account)
        self.passwords.input(password)
        self.login_button2.click()

class testLogin(unittest.TestCase):

    def setUp(self) -> None:
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(3)
        self.driver.get('https://www.rabbitpre.com/')
        self.frameLogin()

    def tearDown(self) -> None:
        time.sleep(5)
        self.driver.quit()

    def frameLogin(self):
        button = self.driver.find_element_by_css_selector('#g-j-signin-btn')
        button.click()
        login_frame = self.driver.find_element_by_css_selector('#sso')
        self.driver.switch_to.frame(login_frame)

    def test_login_success(self):
        logins = LoginPage(self.driver)
        time.sleep(2)
        logins.login('xxx','xxx')
        self.assertIn("工作台", logins.get_title)

    def test_login_failed(self):
        logins = LoginPage(self.driver)
        time.sleep(2)
        logins.login('xxx','xxx')
        self.assertEqual(logins.error_tip.text,'登录密码错误')














